package com.util
{
    import flash.utils.Dictionary;
    
   
    public final class HashMap 
    {
        
        private var map:Dictionary;
        
        
        public function HashMap(useWeakReferences:Boolean = true)
        {
            map = new Dictionary( useWeakReferences );
        }
        
        public function put(key:*, value:*) : void
        {
            map[key] = value;
        }
        
        public function remove(key:*) : void
        {
            delete map[key];
        }
        
        public function containsKey(key:*) : Boolean
        {
            return map[key] != null;
        }
        
        public function containsValue(value:*) : Boolean
        {
            var result:Boolean;
            for ( var key:* in map )
            {
                if (map[key] == value)
                {
                    result = true;
                    break;
                }
            }
            return result;
        }
        
        public function getKey(value:*) : String
        {
            var id:String = null;
            for ( var key:* in map )
            {
                if (map[key] == value)
                {
                    id = key;
                    break;
                }
            }
            return id;
        }
        
        public function getKeys() : Array
        {
            var keys:Array = [];
            for (var key:* in map)
            {
                keys.push( key );
            }
            return keys;
        }
        
        public function getValue(key:*) : *
        {
            return map[key];
        }
        
        public function getValues() : Array
        {
            var values:Array = [];
            for (var key:* in map)
            {
                values.push( map[key] );
            }
            return values;
        }
        
        public function size() : int
        {
            var length:int = 0;
            for (var key:* in map)
            {
                length++;
            }
            return length;
        }
        
        public function isEmpty() : Boolean
        {
            return size() <= 0;
        }
        
        public function reset() : void
        {
            for ( var key:* in map )
            {
                map[key] = null;
            }
        }
        
        public function resetAllExcept(keyId:*) : void
        {
            for ( var key:* in map )
            {
                if ( key != keyId )
                {
                    map[key] = null;
                }
            }
        }
       
        public function clear() : void
        {
            for ( var key:* in map )
            {
                remove( key );
            }
        }
        
        public function clearAllExcept(keyId:*) : void
        {
            for ( var key:* in map )
            {
                if ( key != keyId )
                {
                    remove( key );
                }
            }
        }
    }
}